package br.edu.ufcg.lsd.wbis.ui.client.beans;

import java.io.Serializable;

public class UserInfo implements Serializable {

	public static enum UserPermission {
		ADMIN, COMMON_USER;
	}

	private static final long serialVersionUID = -6271426853461334350L;

	private String login;

	private String oldPassword;

	private String password;

	private String retypedPassword;

	private String name;

	private String email;

	private UserPermission level;

	private boolean authorized;

	public UserInfo() {
		// Do nothing!
	}

	/**
	 * @param result
	 */
	public UserInfo(UserInfo info) {
		setLogin(info.getLogin());
		setPassword(info.getPassword());
		setName(info.getName());
		setEmail(info.getEmail());
		setLevel(info.getLevel());
		setRetypedPassword(info.getRetypedPassword());
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public UserPermission getLevel() {
		return level;
	}

	public void setLevel(UserPermission level) {
		this.level = level;
	}

	public void setRetypedPassword(String retypedPassword) {
		this.retypedPassword = retypedPassword;
	}

	public String getRetypedPassword() {
		return this.retypedPassword;
	}

	/**
	 * @param oldPassword
	 *            the oldPassword to set
	 */
	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

	/**
	 * @return the oldPassword
	 */
	public String getOldPassword() {
		return oldPassword;
	}

	/**
	 * @param authorized
	 *            the authorized to set
	 */
	public void setAuthorized(boolean authorized) {
		this.authorized = authorized;
	}

	/**
	 * @return the authorized
	 */
	public boolean isAuthorized() {
		return authorized;
	}

	public boolean isLoginValid() {
		return login != null && !this.login.isEmpty();
	}

	public boolean isPasswordValid() {
		return this.password != null && !this.password.isEmpty();
	}

	public boolean isPasswordRetyped() {
		return this.password != null && this.password.equals(this.retypedPassword);
	}

	public boolean matchOldPassword(String value) {
		return this.oldPassword != null && this.oldPassword.equals(value);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		StringBuilder bld = new StringBuilder();
		bld.append("Login: ");
		bld.append(this.getLogin());
		bld.append("\n");
		bld.append("Password: ");
		bld.append(this.getPassword());
		bld.append("\n");
		bld.append("Name: ");
		bld.append(this.getName());
		bld.append("\n");
		bld.append("Email: ");
		bld.append(this.getEmail());
		bld.append("\n");
		bld.append("Level: ");
		bld.append(this.getLevel());
		bld.append("\n");
		bld.append("Authorized: ");
		bld.append(this.isAuthorized());
		bld.append("\n");
		return bld.toString();
	}

}
